package ls.jpa.chapter2.dao;

import ls.jpa.chapter2.entity.UserInfo;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.transaction.Transactional;
import java.util.List;

/**
 * @author Barudisshu
 */
@Repository
public class UserDao {

    @PersistenceContext
    private EntityManager em;

    @Transactional
    public UserInfo save(UserInfo userInfo){
        em.persist(userInfo);
        return userInfo;
    }

    public List<UserInfo> getAll(){
        TypedQuery<UserInfo> query = em.createQuery("select u from USER u",UserInfo.class);
        return query.getResultList();
    }
}
